package com.gyt.manager.common.utils;

import lombok.extern.slf4j.Slf4j;

import java.util.Collection;
import java.util.Map;
import java.util.Random;

/**
 * description.
 *
 * @author gyt create on 2021/5/20 9:30
 */
@Slf4j
public class CommonUtil {

    public static boolean isEmpty(Collection<?> collection) {
        return collection == null || collection.isEmpty();
    }

    public static boolean isEmpty(Map<?, ?> map) {
        return map == null || map.isEmpty();
    }

    public static boolean isNotEmpty(Collection<?> collection) {
        return !isEmpty(collection);
    }

    public static boolean isNotEmpty(Map<?, ?> map) {
        return !isEmpty(map);
    }

    /**
     * 随机睡眠 毫秒
     * @param ms
     */
    public static void sleepMsRandom(int ms){
        try {
            long millis = new Random().nextInt(ms);
            Thread.sleep(millis);
        } catch (InterruptedException e) {
            log.warn("sleep failed,thread interrupted", e);
        }
    }

    /**
     * 睡眠 毫秒
     * @param ms
     */
    public static void sleepMs(int ms){
        try {
            Thread.sleep(ms);
        } catch (InterruptedException e) {
            log.warn("sleep failed,thread interrupted", e);
        }
    }
}
